package com.office.automate.service.impl.leave;

import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import com.office.automate.configuration.property.ConfigurationProperties;
import com.office.automate.dataaccess.def.leave.EmployeeLeaveDao;
import com.office.automate.dataaccess.impl.administration.PublicHolidayDaoImplementer;
import com.office.automate.dataaccess.impl.leave.EmployeeLeaveDaoImplementer;
import com.office.automate.dataaccess.impl.user.EmployeeDaoImplementer;
import com.office.automate.email.framework.HandlingEmails;
import com.office.automate.exception.framework.FrontierVisibleException;
import com.office.automate.frontier.utility.DataConversionUtility;
import com.office.automate.leave.data.validator.LeaveRequestDataValidator;
import com.office.automate.model.employee.Employee;
import com.office.automate.model.leave.EmployeeLeave;
import com.office.automate.model.leave.LeaveRequest;
import com.office.automate.model.leave.LieuLeaveRequest;
import com.office.automate.service.def.leave.EmployeeLeaveService;
import com.office.automate.statics.ApplicationStatics;

public class EmployeeLeaveServiceImplementer implements EmployeeLeaveService {

	private EmployeeLeaveDao employeeLeaveDao = new EmployeeLeaveDaoImplementer();
	private LeaveRequestDataValidator leaveRequestDataValidator = new LeaveRequestDataValidator();
	private HandlingEmails handlingEmails = new HandlingEmails();
	private Properties properties = ConfigurationProperties.getProps();
	private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
	private DataConversionUtility dtUtility = new DataConversionUtility();

	public List<EmployeeLeave> getCurrentEntitlementBalance(long anEmployeeId) throws FrontierVisibleException {
		
		return employeeLeaveDao.getCurrentEntitlementBalance(anEmployeeId);
	}

	public EmployeeLeave getCurrentEntitlementBalance(int aFnYear, long anEmployeeId) throws FrontierVisibleException {

		return employeeLeaveDao.getCurrentEntitlementBalance(aFnYear, anEmployeeId);
	}

	public HashMap<String, FrontierVisibleException> validateLeaveRequestDetails(LeaveRequest leaveRequest) throws FrontierVisibleException {
		HashMap<String, FrontierVisibleException> fieldValidationErrors = null;

		leaveRequestDataValidator.validateLeaveRequestDetails(leaveRequest);

		if (leaveRequestDataValidator.isValidationErrorsExist()) {
			fieldValidationErrors = leaveRequestDataValidator.getFieldValidationErrors();
		}
		return fieldValidationErrors;
	}

	public void addLeaveRequest(LeaveRequest leaveRequest) throws FrontierVisibleException {
		Map<String, Object> leaveReqiuestDetails = employeeLeaveDao.addLeaveRequest(leaveRequest);
		Employee leaveRequester = (Employee)leaveReqiuestDetails.get("LeaveRequesterDetails");
		Employee leaveApprover = (Employee)leaveReqiuestDetails.get("LeaveApproverDetails");

		// Send confirmation email to leave approver.
		handlingEmails.sendEmailTo(
						leaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LEAVE_APPROVER_MAIL_SUBJECT"),
										     leaveRequester.getFirstName() + " " + leaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.REQUEST_APPROVE_MAIL, leaveApprover, leaveRequest));

		// Send confirmation email to leave requester.
		handlingEmails.sendEmailTo(
						leaveRequester.getEmail(),
						properties.getProperty("MAIL_LEAVE_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.REQUEST_APPROVE_MAIL, leaveRequester, leaveApprover, leaveRequest));


	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<List> getEmployeeLeaveDetailsPage(Map<String, Object> aQueryCriterias, int aStartingIndex, int aNumberOfRecords) throws FrontierVisibleException {
		List<List> anEmployeeLeaveRequestsList = new ArrayList<List>();

		List<LeaveRequest> employeeLeave = employeeLeaveDao.getEmployeeLeaveRequestsList(aQueryCriterias, aStartingIndex, aNumberOfRecords);
	
		for (LeaveRequest leaveRequest :employeeLeave) {
			int numberOfLeaveDays = dtUtility.getWorkingDaysCountForGivenDateRange(leaveRequest.getFromDate(), leaveRequest.getToDate()) -
										new PublicHolidayDaoImplementer().getAvailablePublicHolidayRecordCountForDateRange(leaveRequest.getFromDate(), leaveRequest.getToDate());
			List anEmployeeLeaveRequestDataRow = new ArrayList();
			anEmployeeLeaveRequestDataRow.add(leaveRequest.getLeaveType());
			anEmployeeLeaveRequestDataRow.add(formatter.format(leaveRequest.getFromDate()));
			anEmployeeLeaveRequestDataRow.add(formatter.format(leaveRequest.getToDate()));
			anEmployeeLeaveRequestDataRow.add(numberOfLeaveDays);
			anEmployeeLeaveRequestDataRow.add(new EmployeeDaoImplementer().getEmployeeName(leaveRequest.getApproverEmployeeId()));
			anEmployeeLeaveRequestDataRow.add(properties.getProperty(leaveRequest.getStatus()));
			anEmployeeLeaveRequestDataRow.add(leaveRequest.getRequestId());
			// TODO need to combine with the attendance details
			anEmployeeLeaveRequestDataRow.add(Boolean.FALSE.toString());
			anEmployeeLeaveRequestsList.add(anEmployeeLeaveRequestDataRow);
		}
		return anEmployeeLeaveRequestsList;
	}

	public int getAvailableEmployeeLeaveRequestsRecordCount(Map<String, Object> aQueryCriterias) throws FrontierVisibleException {

		return employeeLeaveDao.getAvailableEmployeeLeaveRequestsRecordCount(aQueryCriterias);
	}

	public void cancelLeaveRequest(LeaveRequest aLeaveRequest) throws FrontierVisibleException {
		Map<String, Object> leaveReqiuestDetails = employeeLeaveDao.cancelLeaveRequest(aLeaveRequest);

		Employee leaveRequester = (Employee)leaveReqiuestDetails.get("LeaveRequesterDetails");
		Employee leaveApprover = (Employee)leaveReqiuestDetails.get("LeaveApproverDetails");
		LeaveRequest leaveRequest = (LeaveRequest)leaveReqiuestDetails.get("LeaveRequest");

		// Send confirmation email to leave approver.
		handlingEmails.sendEmailTo(
						leaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LEAVE_CANCEL_APPROVER_MAIL_SUBJECT"),
										     leaveRequester.getFirstName() + " " + leaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.CANCEL_MAIL, leaveApprover, leaveRequest));

		// Send confirmation email to leave requester.
		handlingEmails.sendEmailTo(
						leaveRequester.getEmail(),
						properties.getProperty("MAIL_LEAVE_CANCEL_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.CANCEL_MAIL, leaveRequester, leaveApprover, leaveRequest));
		
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<List> getEmployeeLeaveApprovalRequestPage(int aStartingIndex, int aNumberOfRecords, long aCurrentLoginUserId) throws FrontierVisibleException {
		List<List> anEmployeeLeaveApprovalRequestsList = new ArrayList<List>();
		List<LeaveRequest> employeeLeave = employeeLeaveDao.getEmployeeLeaveApprovalRequestsList(aCurrentLoginUserId, aStartingIndex, aNumberOfRecords);
		for (LeaveRequest leaveRequest :employeeLeave) {
			int numberOfLeaveDays = dtUtility.getWorkingDaysCountForGivenDateRange(leaveRequest.getFromDate(), leaveRequest.getToDate()) -
										new PublicHolidayDaoImplementer().getAvailablePublicHolidayRecordCountForDateRange(leaveRequest.getFromDate(), leaveRequest.getToDate());
			List anEmployeeLeaveApprovalRequestDataRow = new ArrayList();
			anEmployeeLeaveApprovalRequestDataRow.add(leaveRequest.getLeaveType());
			anEmployeeLeaveApprovalRequestDataRow.add(formatter.format(leaveRequest.getFromDate()));
			anEmployeeLeaveApprovalRequestDataRow.add(formatter.format(leaveRequest.getToDate()));
			anEmployeeLeaveApprovalRequestDataRow.add(numberOfLeaveDays);
			anEmployeeLeaveApprovalRequestDataRow.add(new EmployeeDaoImplementer().getEmployeeName(leaveRequest.getEmployeeId()));
			anEmployeeLeaveApprovalRequestDataRow.add(leaveRequest.getRequestId());
			anEmployeeLeaveApprovalRequestsList.add(anEmployeeLeaveApprovalRequestDataRow);
		}
		return anEmployeeLeaveApprovalRequestsList;
	}

	public int getAvailableEmployeeLeaveApprovalRequestRecordCount(long aCurrentLoginUserId) throws FrontierVisibleException {

		return employeeLeaveDao.getAvailableEmployeeLeaveApprovalRequestRecordCount(aCurrentLoginUserId);
	}

	public void approveLeaveRequest(long aRequestId) throws FrontierVisibleException {
		Map<String, Object> leaveReqiuestDetails = employeeLeaveDao.approveLeaveRequest(aRequestId);
		Employee leaveRequester = (Employee)leaveReqiuestDetails.get("LeaveRequesterDetails");
		Employee leaveApprover = (Employee)leaveReqiuestDetails.get("LeaveApproverDetails");
		LeaveRequest leaveRequest = (LeaveRequest)leaveReqiuestDetails.get("LeaveRequest");

		// Send confirmation email to leave approver.
		handlingEmails.sendEmailTo(
						leaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LEAVE_APPROVE_APPROVER_MAIL_SUBJECT"),
										     leaveRequester.getFirstName() + " " + leaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.APPROVED_MAIL, leaveApprover, leaveRequest));

		// Send confirmation email to leave requester.
		handlingEmails.sendEmailTo(
						leaveRequester.getEmail(),
						properties.getProperty("MAIL_LEAVE_APPROVE_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.APPROVED_MAIL, leaveRequester, leaveApprover, leaveRequest));
	}

	public void rejectLeaveRequest(long aRequestId) throws FrontierVisibleException {
		Map<String, Object> leaveReqiuestDetails = employeeLeaveDao.rejectLeaveRequest(aRequestId);
		Employee leaveRequester = (Employee)leaveReqiuestDetails.get("LeaveRequesterDetails");
		Employee leaveApprover = (Employee)leaveReqiuestDetails.get("LeaveApproverDetails");
		LeaveRequest leaveRequest = (LeaveRequest)leaveReqiuestDetails.get("LeaveRequest");

		// Send confirmation email to leave approver.
		handlingEmails.sendEmailTo(
						leaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LEAVE_REJECT_APPROVER_MAIL_SUBJECT"),
										     leaveRequester.getFirstName() + " " + leaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.REJECT_MAIL, leaveApprover, leaveRequest));

		// Send confirmation email to leave requester.
		handlingEmails.sendEmailTo(
						leaveRequester.getEmail(),
						properties.getProperty("MAIL_LEAVE_REJECT_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.REJECT_MAIL, leaveRequester, leaveApprover, leaveRequest));
	}

	private String getEmailBodyForApprover(String aMailRequestType, Employee aLeaveApprover, LeaveRequest aLeaveRequest) {
		String emailBodyText = "";
		String emailBodyTemplate = "";
		if (aMailRequestType.equals(ApplicationStatics.REQUEST_APPROVE_MAIL)){
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_APPROVER_MAIL_BODY");			
		} else if (aMailRequestType.equals(ApplicationStatics.CANCEL_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_CANCEL_APPROVER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.APPROVED_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_APPROVE_APPROVER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.REJECT_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_REJECT_APPROVER_MAIL_BODY");
		}

		emailBodyText = MessageFormat.format(emailBodyTemplate,
											 aLeaveApprover.getFirstName() + " " + aLeaveApprover.getLastName(),
											 formatter.format(aLeaveRequest.getFromDate()),
											 formatter.format(aLeaveRequest.getToDate()),
											 aLeaveRequest.getNumberOfDays(),
											 aLeaveRequest.getReason());
		return emailBodyText;
	}

	private String getEmailBodyForRequester(String aMailRequestType, Employee aLeaveRequester, Employee aLeaveApprover, LeaveRequest aLeaveRequest) {
		String emailBodyText = "";
		String emailBodyTemplate = "";
		if (aMailRequestType.equals(ApplicationStatics.REQUEST_APPROVE_MAIL)){
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_REQUESTER_MAIL_BODY");			
		} else if (aMailRequestType.equals(ApplicationStatics.CANCEL_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_CANCEL_REQUESTER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.APPROVED_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_APPROVE_REQUESTER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.REJECT_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LEAVE_REJECT_REQUESTER_MAIL_BODY");
		}
		emailBodyText = MessageFormat.format(emailBodyTemplate,
											 aLeaveRequest.getNumberOfDays(),
											 formatter.format(aLeaveRequest.getFromDate()),
											 formatter.format(aLeaveRequest.getToDate()),
											 aLeaveApprover.getFirstName() + " " + aLeaveApprover.getLastName());
		return emailBodyText;
	}

	public HashMap<String, FrontierVisibleException> validateLieuLeaveRequestDetails(LieuLeaveRequest lieuLeaveRequest) throws FrontierVisibleException {
		HashMap<String, FrontierVisibleException> fieldValidationErrors = null;

		leaveRequestDataValidator.validateLieuLeaveRequestDetails(lieuLeaveRequest);

		if (leaveRequestDataValidator.isValidationErrorsExist()) {
			fieldValidationErrors = leaveRequestDataValidator.getFieldValidationErrors();
		}
		return fieldValidationErrors;
	}

	public void addLieuLeaveRequest(LieuLeaveRequest lieuLeaveRequest) throws FrontierVisibleException {
		Map<String, Object> leaveReqiuestDetails = employeeLeaveDao.addLieuLeaveRequest(lieuLeaveRequest);
		Employee lieuLeaveRequester = (Employee)leaveReqiuestDetails.get("LieuLeaveRequesterDetails");
		Employee lieuLeaveApprover = (Employee)leaveReqiuestDetails.get("LieuLeaveApproverDetails");

		// Send confirmation email to leave approver.
		handlingEmails.sendEmailTo(
						lieuLeaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LIEU_LEAVE_APPROVER_MAIL_SUBJECT"),
											 lieuLeaveRequester.getFirstName() + " " + lieuLeaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.LIEU_LEAVE_REQUEST_APPROVE_MAIL, lieuLeaveApprover, lieuLeaveRequest));

		// Send confirmation email to leave requester.
		handlingEmails.sendEmailTo(
						lieuLeaveRequester.getEmail(),
						properties.getProperty("MAIL_LIEU_LEAVE_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.LIEU_LEAVE_REQUEST_APPROVE_MAIL, lieuLeaveRequester, lieuLeaveApprover, lieuLeaveRequest));

		
	}

	public void cancelLieuLeaveRequest(long aRequestId) throws FrontierVisibleException {
		Map<String, Object> leaveReqiuestDetails = employeeLeaveDao.cancelLieuLeaveRequest(aRequestId);

		Employee leaveRequester = (Employee)leaveReqiuestDetails.get("LieuLeaveRequesterDetails");
		Employee leaveApprover = (Employee)leaveReqiuestDetails.get("LieuLeaveApproverDetails");
		LieuLeaveRequest lieuLeaveRequest = (LieuLeaveRequest)leaveReqiuestDetails.get("LieuLeaveRequest");

		// Send confirmation email to lieu leave approver.
		handlingEmails.sendEmailTo(
						leaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LIEU_LEAVE_CANCEL_APPROVER_MAIL_SUBJECT"),
										     leaveRequester.getFirstName() + " " + leaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.CANCEL_MAIL, leaveApprover, lieuLeaveRequest));

		// Send confirmation email to lieu leave requester.
		handlingEmails.sendEmailTo(
						leaveRequester.getEmail(),
						properties.getProperty("MAIL_LIEU_LEAVE_CANCEL_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.CANCEL_MAIL, leaveRequester, leaveApprover, lieuLeaveRequest));
		
	}

	public void approveLieuLeaveRequest(long aRequestId) throws FrontierVisibleException {
		Map<String, Object> lieuLeaveReqiuestDetails = employeeLeaveDao.approveLieuLeaveRequest(aRequestId);
		Employee leaveRequester = (Employee)lieuLeaveReqiuestDetails.get("LeaveRequesterDetails");
		Employee leaveApprover = (Employee)lieuLeaveReqiuestDetails.get("LeaveApproverDetails");
		LieuLeaveRequest lieuLeaveRequest = (LieuLeaveRequest)lieuLeaveReqiuestDetails.get("LieuLeaveRequest");

		// Send confirmation email to leave approver.
		handlingEmails.sendEmailTo(
						leaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LIEU_LEAVE_APPROVE_APPROVER_MAIL_SUBJECT"),
										     leaveRequester.getFirstName() + " " + leaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.APPROVED_MAIL, leaveApprover, lieuLeaveRequest));

		// Send confirmation email to leave requester.
		handlingEmails.sendEmailTo(
						leaveRequester.getEmail(),
						properties.getProperty("MAIL_LIEU_LEAVE_APPROVE_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.APPROVED_MAIL, leaveRequester, leaveApprover, lieuLeaveRequest));
	}

	public void rejectLieuLeaveRequest(long aRequestId) throws FrontierVisibleException {
		Map<String, Object> lieuLeaveReqiuestDetails = employeeLeaveDao.rejectLieuLeaveRequest(aRequestId);
		Employee leaveRequester = (Employee)lieuLeaveReqiuestDetails.get("LeaveRequesterDetails");
		Employee leaveApprover = (Employee)lieuLeaveReqiuestDetails.get("LeaveApproverDetails");
		LieuLeaveRequest lieuLeaveRequest = (LieuLeaveRequest)lieuLeaveReqiuestDetails.get("LieuLeaveRequest");

		// Send confirmation email to leave approver.
		handlingEmails.sendEmailTo(
						leaveApprover.getEmail(),
						MessageFormat.format(properties.getProperty("MAIL_LIEU_LEAVE_REJECT_APPROVER_MAIL_SUBJECT"),
										     leaveRequester.getFirstName() + " " + leaveRequester.getLastName()),
						getEmailBodyForApprover(ApplicationStatics.REJECT_MAIL, leaveApprover, lieuLeaveRequest));

		// Send confirmation email to leave requester.
		handlingEmails.sendEmailTo(
						leaveRequester.getEmail(),
						properties.getProperty("MAIL_LIEU_LEAVE_REJECT_REQUESTER_MAIL_SUBJECT"),
						getEmailBodyForRequester(ApplicationStatics.REJECT_MAIL, leaveRequester, leaveApprover, lieuLeaveRequest));
	}

	private String getEmailBodyForApprover(String aMailRequestType, Employee aLeaveApprover, LieuLeaveRequest lieuLeaveRequest) {
		String emailBodyText = "";
		String emailBodyTemplate = "";
		if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_REQUEST_APPROVE_MAIL)){
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_APPROVER_MAIL_BODY");			
		} else if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_CANCEL_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_CANCEL_APPROVER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_APPROVED_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_APPROVE_APPROVER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_REJECT_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_REJECT_APPROVER_MAIL_BODY");
		}

		emailBodyText = MessageFormat.format(emailBodyTemplate,
											 aLeaveApprover.getFirstName() + " " + aLeaveApprover.getLastName(),
											 formatter.format(lieuLeaveRequest.getLieuLeaveDate()),
											 lieuLeaveRequest.getReasonForLeave());
		return emailBodyText;
	}

	private String getEmailBodyForRequester(String aMailRequestType, Employee aLeaveRequester, Employee aLeaveApprover, LieuLeaveRequest lieuLeaveRequest) {
		String emailBodyText = "";
		String emailBodyTemplate = "";
		if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_REQUEST_APPROVE_MAIL)){
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_REQUESTER_MAIL_BODY");			
		} else if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_CANCEL_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_CANCEL_REQUESTER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_APPROVED_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_APPROVE_REQUESTER_MAIL_BODY");
		} else if (aMailRequestType.equals(ApplicationStatics.LIEU_LEAVE_REJECT_MAIL)) {
			emailBodyTemplate = properties.getProperty("MAIL_LIEU_LEAVE_REJECT_REQUESTER_MAIL_BODY");
		}
		emailBodyText = MessageFormat.format(emailBodyTemplate,
											 formatter.format(lieuLeaveRequest.getLieuLeaveDate()),
											 aLeaveApprover.getFirstName() + " " + aLeaveApprover.getLastName());
		return emailBodyText;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<List> getEmployeeLieuLeaveRequestPage(Map<String, Object> aQueryCriterias, int aStartingIndex, int aNumberOfRecords) throws FrontierVisibleException {
		List<List> anEmployeeLieuLeaveRequestsList = new ArrayList<List>();

		List<LieuLeaveRequest> lieuLeaveRequestList = employeeLeaveDao.getEmployeeLieuLeaveRequestsList(aQueryCriterias, aStartingIndex, aNumberOfRecords);
	
		for (LieuLeaveRequest lieuLeaveRequest :lieuLeaveRequestList) {

			List anEmployeeLieuLeaveRequestDataRow = new ArrayList();
			anEmployeeLieuLeaveRequestDataRow.add(formatter.format(lieuLeaveRequest.getLieuLeaveDate()));
			anEmployeeLieuLeaveRequestDataRow.add(new EmployeeDaoImplementer().getEmployeeName(lieuLeaveRequest.getApproverEmployeeId()));
			anEmployeeLieuLeaveRequestDataRow.add(properties.getProperty(lieuLeaveRequest.getStatus()));
			anEmployeeLieuLeaveRequestDataRow.add(lieuLeaveRequest.getReasonForLeave());
			anEmployeeLieuLeaveRequestDataRow.add(lieuLeaveRequest.getRequestID());
			anEmployeeLieuLeaveRequestsList.add(anEmployeeLieuLeaveRequestDataRow);
		}
		return anEmployeeLieuLeaveRequestsList;
	}

	public int getAvailableEmployeeLieuLeaveRequestsRecordCount(Map<String, Object> aQueryCriterias) throws FrontierVisibleException {

		return employeeLeaveDao.getAvailableEmployeeLieuLeaveRequestsRecordCount(aQueryCriterias);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<List> getEmployeeLieuLeaveApprovalRequestPage(int aStartingIndex, int aNumberOfRecords, long aCurrentLoginUserId) throws FrontierVisibleException {
		List<List> anEmployeeLieuLeaveRequestList = new ArrayList<List>();

		List<LieuLeaveRequest> lieuLeaveRequestList = employeeLeaveDao.getEmployeeLieuLeaveApprovalRequestsList(aCurrentLoginUserId, aStartingIndex, aNumberOfRecords);
	
		for (LieuLeaveRequest lieuLeaveRequest :lieuLeaveRequestList) {
			List anEmployeeLieuLeaveDataRow = new ArrayList();
			anEmployeeLieuLeaveDataRow.add(formatter.format(lieuLeaveRequest.getLieuLeaveDate()));
			anEmployeeLieuLeaveDataRow.add(new EmployeeDaoImplementer().getEmployeeName(lieuLeaveRequest.getEmployeeId()));
			anEmployeeLieuLeaveDataRow.add(lieuLeaveRequest.getReasonForLeave());
			anEmployeeLieuLeaveDataRow.add(lieuLeaveRequest.getRequestID());
			anEmployeeLieuLeaveRequestList.add(anEmployeeLieuLeaveDataRow);
		}
		return anEmployeeLieuLeaveRequestList;
	}

	public int getAvailableEmployeeLieuLeaveApprovalRequestRecordCount(long aCurrentLoginUserId) throws FrontierVisibleException {

		return employeeLeaveDao.getAvailableEmployeeLieuLeaveApprovalRequestRecordCount(aCurrentLoginUserId);
	}
}
